package pso;

public class Particle {
	private Point position;
	private Point velocity;
	private Point currentOptimalPosition;
	private double currentOptimalValue;
	private BlackBoxFunction function;
	public Particle(Point position, Point velocity, BlackBoxFunction function) {
		this.setCurrentOptimalPosition(position);
		this.setPosition(position);
		this.setVelocity(velocity);
		this.function = function;
		currentOptimalValue = function.evaluate(position);
	}
	public Point getPosition() {
		return position;
	}
	public void setPosition(Point position) {
		this.position = position;
	}
	public Point getVelocity() {
		return velocity;
	}
	public void setVelocity(Point velocity) {
		this.velocity = velocity;
	}
	public Point getCurrentOptimalPosition() {
		return currentOptimalPosition;
	}
	public void setCurrentOptimalPosition(Point currentOptimalPosition) {
		this.currentOptimalPosition = currentOptimalPosition;
	}
	
	public double evaluateFunctionOnParticle(){
		double currentResult = function.evaluate(getPosition());
		if(currentResult <= getCurrentOptimalValue()){
			currentOptimalValue = currentResult;
			setCurrentOptimalPosition(getPosition());
		}
		return currentResult;
	}
	public double getCurrentOptimalValue(){
		return currentOptimalValue;
	}
}
